class Watcher {
  constructor (vm, key, cb) {
    this.vm = vm
    this.key = key
    this.cb = cb
    //把当前的对象记录到Dep的target
    Dep.target = this
    // 这里会触发get
    this.oldValue = vm[key]
    // 触发get后清空
    Dep.target = null
  }
  // 当数据发生变化时更新视图
  update () {
    let newValue = this.vm[this.key]
    if (this.newValue === this.oldValue) return
    this.cb(newValue)
  }
}